package com.youthfilmic.yuejian.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


/**
 * @title 在线程中获取的spring bean
 * @author Dxywx
 * @time 2015.8.8
 * 
 * */
@Component
public class SpringApplicationContextHolder implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        SpringApplicationContextHolder.context = context;
    }
   
    public static Object getSpringBean(String beanName) {

        return context==null?null:context.getBean(beanName);
    }

    public static String[] getBeanDefinitionNames() {

        return context.getBeanDefinitionNames();
    }

    public static void printNames(){
        String[] d = SpringApplicationContextHolder.getBeanDefinitionNames();
        for (int i = 0;i < d.length ; i++){
            System.out.println(d[i]);
        }
        System.out.println();
    }
    
}